package com.google.guava.eventbus.service;

import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import com.google.guava.eventbus.events.Request;
import com.google.guava.eventbus.events.Response;

/**
 * @author fuc
 * @create 2020-10-06
 */
public class QueryService {
  private static final Log log = LogFactory.get();

  private final EventBus eventBus;

  public QueryService(EventBus eventBus) {
    this.eventBus = eventBus;
    this.eventBus.register(this);
  }

  public void query(String orderNo) {
    log.info("Received the orderNo [{}]", orderNo);
    this.eventBus.post(new Request(orderNo));
  }

  @Subscribe
  public void handleResponse(Response response) {
    log.info("{}", response);
  }
}
